#include <iostream>
#include <string>
#include <map>
#include <ctype.h>
using namespace std;
typedef pair<int, int> pii;
int main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
    string head;
    while(getline(cin, head)){
        if(head.empty()) continue;
        map<pii, char> ma;
        int k=0, j=1;
        for(int i=0; i<head.size(); ++i){
            if(k < (1<<j)-1) {
                pii pair = make_pair(j, k);
                ma.insert(make_pair(make_pair(j, k), head[i]));
                k++;}
            else{
                k=0;
                j++;
                ma.insert(make_pair(make_pair(j, k), head[i]));
                k++;
            }
        }

        string ans;
        while(1){
            string length;
            for(int i=1; i<=3; i++){char ch; cin >> ch; length.push_back(ch);}
            int len = stoi(length, nullptr, 2);
            if(len == 0) { break;}

            while(1){
                string in;
                for(int i=0; i<len; i++){
                    char ch; cin >> ch; in.push_back(ch);
                }
                int val = stoi(in, nullptr, 2);

                if(val == (1<<len)-1) break;
                else ans.push_back(ma[make_pair(len, val)]);
            }
        }
        cout << ans << "\n";
    }
    return 0;
}
